package com.houger.ddd.redpacket.application;

import cn.hutool.core.date.DateTime;
import com.houger.ddd.redpacket.facade.dto.RedPacketDto;
import com.houger.ddd.redpacket.domain.RedPacketDomain;
import com.houger.ddd.redpacket.infra.entity.RedPacket;

/**
 * @author Houger.
 * @date 2024年04月18日 18:18.
 */
public class RedPacketAdaptor {
    public static RedPacketDomain toDomain(RedPacketDto dto) {

        return RedPacketDomain.builder()
            .redPacketId(dto.getRedPacketId())
            .totalAmount(dto.getTotalAmount())
            .totalCount(dto.getTotalCount())
            .residualAmount(dto.getTotalAmount())
            .residualCount(dto.getTotalCount())
            .residualCount(dto.getTotalCount())
            .userId(dto.getUserId())
            .sendTime(DateTime.now().toString())
            .isOnlyMinAmount(dto.getIsOnlyMinAmount())
            .build();
    }

    public static RedPacket toEntity(RedPacketDomain domain) {
        final RedPacket redPacket = new RedPacket();
        redPacket.setRedPacketId(domain.getRedPacketId());
        redPacket.setTotalAmount(domain.getTotalAmount());
        redPacket.setTotalCount(domain.getTotalCount());
        redPacket.setResidualAmount(domain.getResidualAmount());
        redPacket.setResidualCount(domain.getResidualCount());
        redPacket.setIsOnlyMinAmount(domain.getIsOnlyMinAmount());
        redPacket.setUserId(domain.getUserId());
        redPacket.setSendTime(domain.getSendTime());
        return redPacket;
    }

    public static RedPacketDto entityToDto(RedPacket entity) {
        final RedPacketDto dto = RedPacketDto.builder()
            .redPacketId(entity.getRedPacketId())
            .totalAmount(entity.getTotalAmount())
            .totalCount(entity.getTotalCount())
            .userId(entity.getUserId())
            .residualAmount(entity.getResidualAmount())
            .residualCount(entity.getResidualCount())
            .build();
        dto.setSendTime(entity.getSendTime());
        dto.setBurnoutTime(entity.getBurnoutTime());
        return dto;
    }

}
